package com.example.administrator.about_huanxin.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.about_huanxin.R;
import com.example.administrator.about_huanxin.model.UserEntity;
import com.squareup.picasso.Picasso;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/3/24 0024.
 */

public class HaoYouAdapter extends RecyclerView.Adapter<HaoYouViewHolder> {

    private Context mContext;
    private LayoutInflater inflater;
    private List<UserEntity> mDatas;

    public HaoYouAdapter(Context mContext, List<UserEntity> mDatas) {
        this.mContext = mContext;
        this.mDatas = mDatas;
        inflater = LayoutInflater.from(mContext);
    }

    public void setRefresh(List<UserEntity> users){
        this.mDatas = users;
        notifyDataSetChanged();
    }

    @Override
    public HaoYouViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        HaoYouViewHolder holder = new HaoYouViewHolder(inflater.inflate(R.layout.adapter_search, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(HaoYouViewHolder holder, int position) {
        holder.searchItemBtn.setVisibility(View.GONE);
        if (!TextUtils.isEmpty(mDatas.get(position).getIcon().getUrl())) {
            Picasso.with(mContext).load(mDatas.get(position).getIcon().getUrl()).into(holder.searchItemImg);
        }
        holder.searchItemName.setText(mDatas.get(position).getNickname());
        holder.searchItemTime.setText(mDatas.get(position).getUpdatedAt());
    }

    @Override
    public int getItemCount() {
        return mDatas == null ? 0 : mDatas.size();
    }
}

class HaoYouViewHolder extends RecyclerView.ViewHolder {
    @Bind(R.id.search_item_img)
    ImageView searchItemImg;
    @Bind(R.id.search_item_name)
    TextView searchItemName;
    @Bind(R.id.search_item_time)
    TextView searchItemTime;
    @Bind(R.id.search_item_btn)
    Button searchItemBtn;
    public HaoYouViewHolder(View itemView) {
        super(itemView);
        ButterKnife.bind(this,itemView);
    }
}
